class Card

include Enum

  attr_reader :rank #0..8
  attr_reader :suit #0..3

  attr_accessor :isTrump

  #working prop (for disable not allowed cards)
  def enabled?
    @enabled
  end
  def enabled=(value)
    @enabled = value
  end

  def initialize(rank, suit)
    @rank = Integer(rank)
    @suit = Integer(suit)

    #initialise default value
    @enabled = false if @enabled.nil?
  end

  # Relative weight of current card in diapason's 1..18
  def value
      result = rank
      if (isTrump)
        result += 9
      end
    return result
  end

  def compare(card)
    return (self.rank == card.rank && self.suit == card.suit)
  end

  def compareIsStronger(card)
    if (self.suit == card.suit)
      return  self.value < card.value
    else
      return  self.value < card.value && card.isTrump
    end
  end

  def serialize
    [@rank, @suit].join(CARD_DELIMITER)
  end

  def deserialize(string)
    record = string.split(CARD_DELIMITER)
    @rank = Integer(record.first)
    @suit = Integer(record.last)
  end


  def to_s
    [ RANK_MAP[@rank], SUITS_MAP[@suit] ].join
  end

  def image
    filename = [ IMAGE_SUITS_MAP[@suit], IMAGE_RANK_MAP[@rank] ].join('---')
    #"wildcards-96x144/"
    return "wildcards-blue/" + filename  + ".png"
  end
end